local zhushuang = fk.CreateSkill {
    name = "kq__zhushuang",
}

Fk:loadTranslationTable {
    ["kq__zhushuang"] = "逐霜",
    [":kq__zhushuang"] = "结束阶段，你可以对一名本回合受到过伤害或使用过非基本牌的角色造成1点冰冻伤害，"..
    "若你因此弃置的牌花色相同，你对该角色重复此流程。",

    ["#zhushuang__choose"] = "逐霜：选择一名角色，对其造成1点冰冻伤害。",
    ["#zhushuang__choose2"] = "逐霜：是否重复此流程",
    ["#zhushuang_yes"] = "是",
    ["#zhushuang_no"] = "否",
}

zhushuang:addEffect(fk.EventPhaseStart, {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        local flag = #room.logic:getActualDamageEvents(999, function (p)
            return true end, Player.HistoryTurn) + 
            #room.logic:getEventsByRule(GameEvent.UseCard, 999, function (p)
            return p.data.card.type ~= Card.Basic end, nil, Player.HistoryTurn)
        return target == player and player:hasSkill(zhushuang.name) and player.phase == Player.Finish and flag ~= 0
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local tgt = {}
        room.logic:getActualDamageEvents(999, function (p) local data = p.data
            table.insertIfNeed(tgt, data.to) end, Player.HistoryTurn)
        room.logic:getEventsByRule(GameEvent.UseCard, 999, function (p)
            local data = p.data
            if data.card.type ~= Card.TypeBasic then
                table.insertIfNeed(tgt, data.from)
                end
            end, nil, Player.HistoryTurn)
        local t = room:askToChoosePlayers(player, {
            targets = tgt,
            min_num = 1,
            max_num = 1,
            prompt = "#zhushuang__choose",
            skill_name = zhushuang.name,
            cancelable = true
        })
        if #t == 0 then return end
        local flag = true
        local flag1 = false
        local history_dis = 0
        while flag == true do
            flag = false
            flag1 = false
            if #t[1]:getCardIds("he") == 0 then flag1 = true end
            room:damage({
                from = player,
                to = t[1],
                damage = 1,
                damageType = fk.IceDamage,
                skillName = zhushuang.name,
            })
            local cards = {}
            local dis = 0
            if flag1 == false then
                room.logic:getEventsByRule(GameEvent.MoveCards, 999, function(p)
                    local data = p.data
                    for _, i in ipairs(data) do
                        if i.skillName == "ice_damage_skill" and i.proposer == player then
                            for _, j in ipairs(i.moveInfo) do
                                local card = Fk:getCardById(j.cardId)
                                table.insert(cards, card)
                                dis = dis + 1
                            end
                        end
                    end
                end, nil, Player.HistoryPhase)
                if dis - history_dis == 0 then flag = false
                else if dis - history_dis == 1 then flag = true
                else if cards[1].suit == cards[2].suit then flag = true end end end
            end
            history_dis = dis
            if flag == true then
                local choice = room:askToChoice(player, {
                    choices = {"#zhushuang_yes", "#zhushuang_no"},
                    skill_name = zhushuang.name,
                    cancelable = false,
                    prompt = "#zhushuang__choose2"
                })
                if choice == "#zhushuang_no" then flag = false end
            end
        end
    end
})

return zhushuang